import random
import pygame
from game import Game

Game.seconds = 0


class Monster:
    def __init__(self, left: int, top: int, speed, hp):
        self.monster_images = pygame.image.load("Img/怪物左.png").convert_alpha()
        self.monster_images2 = pygame.image.load("Img/怪物左2.png")
        self.monster_images3 = pygame.image.load("Img/怪物左3.png")
        self.monster_images4 = pygame.image.load("Img/怪物左4.png")
        self.monster_images5 = pygame.image.load("Img/怪物左5.png")

        self.monster_image1 = pygame.transform.scale(self.monster_images, (70, 70))
        self.monster_image2 = pygame.transform.scale(self.monster_images2, (70, 70))
        self.monster_image3 = pygame.transform.scale(self.monster_images3, (70, 70))
        self.monster_image4 = pygame.transform.scale(self.monster_images4, (70, 70))
        self.monster_image5 = pygame.transform.scale(self.monster_images5, (70, 70))

        self.monster_image_Boss2 = pygame.image.load("Img/怪物左.png")
        self.monster_image_Boss = pygame.transform.scale(self.monster_image_Boss2, (300, 300))

        if 0 < Game.seconds < 240:
            self.Monster_rect = self.monster_image1.get_rect()
        else:
            self.Monster_rect = self.monster_image_Boss.get_rect()

        self.Monster_rect.left = left
        self.Monster_rect.top = top
        self.Monster_speed = speed
        self.monster_y = random.randint(500, 600)
        self.color = (255, 0, 0)
        # 设置长方形的位置和尺寸（例如：x=50, y=50, 宽度=100, 高度=50）
        # 绘制长方形
        self.box_w = hp
        self.box_h = 12

        Game.random_monster1 = self.monster_image1
        Game.random_monster2 = [self.monster_image1, self.monster_image2]
        Game.random_monster3 = [self.monster_image1, self.monster_image2, self.monster_image3]
        Game.random_monster4 = [self.monster_image1, self.monster_image2, self.monster_image3, self.monster_image4]
        Game.random_monster5 = [self.monster_image1, self.monster_image2, self.monster_image3, self.monster_image4,
                                self.monster_image5]

        self.shijian_1 = 30
        self.shijian_2 = 80
        self.shijian_3 = 140
        self.shijian_4 = 180
        self.shijian_5 = 210

        self.shijian_max = 240
        self.shijian_max_2 = 250
        self.boss_font_size = 14

        if self.shijian_1 <= Game.seconds <= self.shijian_max:
            self.monster_image = self.monster_image1
        if self.shijian_2 <= Game.seconds <= self.shijian_max:
            self.monster_image = random.choice(Game.random_monster2)
        if self.shijian_3 <= Game.seconds <= self.shijian_max:
            self.monster_image = random.choice(Game.random_monster3)
        if self.shijian_4 <= Game.seconds <= self.shijian_max:
            self.monster_image = random.choice(Game.random_monster4)
        if self.shijian_5 <= Game.seconds <= self.shijian_max:
            self.monster_image = random.choice(Game.random_monster5)
        if self.shijian_max < Game.seconds <= self.shijian_max_2:
            self.monster_image = self.monster_image_Boss
            self.boss_font_size = 20

        self.font = pygame.font.Font("Font/font.ttf", self.boss_font_size)

        self.text = "0"

    def monster_xinxi(self):

        if self.monster_image == self.monster_image1:
            self.text = "LV:1"
            self.Monster_speed = 1
        if self.monster_image == self.monster_image2 and self.shijian_2 < Game.seconds < self.shijian_max:
            self.text = "LV:2"
            self.Monster_speed = 2
        if self.monster_image == self.monster_image3 and self.shijian_3 < Game.seconds < self.shijian_max:
            self.text = "LV:3"
            self.Monster_speed = 3
        if self.monster_image == self.monster_image4 and self.shijian_4 < Game.seconds < self.shijian_max:
            self.text = "LV:4"
            self.Monster_speed = 4
        if self.monster_image == self.monster_image5 and self.shijian_5 < Game.seconds < self.shijian_max:
            self.text = "LV:5"
            self.Monster_speed = 5
        if self.monster_image == self.monster_image_Boss and self.shijian_max <= Game.seconds <= self.shijian_max_2:
            # self.box_w = 2000
            self.text = "           LV:999999999999999999999999999999 WARNING! BOSS：加央"
            self.Monster_speed = 1

    def monster_display(self):
        Game.window.fill(self.color, (self.Monster_rect.x, self.Monster_rect.y - 15, self.box_w, self.box_h))
        Game.window.blit(self.monster_image, (self.Monster_rect.left, self.Monster_rect.top))
        monster_text = self.font.render(self.text, True, (0, 0, 0))
        Game.window.blit(monster_text, (self.Monster_rect.left + 15, self.Monster_rect.top - 18))

    def monster_go(self):
        self.Monster_rect.left -= self.Monster_speed
